Skip to content

guard negative operands in MathLib::value shift operators#8639

Open
metsw24-max wants to merge 1 commit into
cppcheck-opensource:mainfrom
metsw24-max:mathlib-value-shift-negative-guard
Open

guard negative operands in MathLib::value shift operators#8639
metsw24-max wants to merge 1 commit into
cppcheck-opensource:mainfrom
metsw24-max:mathlib-value-shift-negative-guard

Conversation

@metsw24-max

Copy link
Copy Markdown

the value shift operators only reject a count >= bigint_bits, so MathLib::value::shiftLeft still left-shifts a negative value and both shiftLeft and shiftRight still shift by a negative count, which is undefined behaviour. it is reachable when folding a template argument like 0x8000000000000000 << 1 in simplifyNumericCalculations, since MathLib::isNegative only checks for a leading minus while a large hex literal parses to a negative bigint and the guard there lets it through. mirror the negative-operand check calculate.h already uses and return the operand unchanged, as is already done for oversized counts. ubsan flags the left shift at mathlib.cpp:272 on that input.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant